import {FormControl} from '@angular/forms';
export class StaticValidators {
  static userNameStrength(control: FormControl): {[s: string]: boolean} {
    const normal = new RegExp(/^[\u4E00-\u9FA5A-Za-z0-9_]{4,20}$/);
    if (control.value && !normal.test(control.value)) {
      return {'userNameStrength': true};
    }
    return null;
  }
  static passwordStrength (value: any) {
    const weak = new RegExp(/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/);
    const middle = new RegExp(/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{10,20}$/);
    const strong = new RegExp(/((?=[a-z])(?=.*[#@!~%^&*])|(?=.*\d)(?=.*[#@!~%^&*]))[a-z\d#@!~%^&*]{6,20}$/);
    if (strong.test(value)) {
      return 3;
    }else if (middle.test(value)) {
      return 2;
    } else if (weak.test(value)) {
      return 1;
    } else {
      return 0;
    }
  }
  static checkPassword(control: FormControl): {[s: string]: boolean} {
   // this.user.password = control.value;
    const normal = new RegExp(/^(?![\d]+$)(?![a-zA-Z]+$)(?![!#$%^&*]+$)[\da-zA-Z!#$%^&*]{6,20}$/);
    if (control.value && !normal.test(control.value)) {
      return {'passwordIntensity': true};
    }
    return null;
  }
  static checkPhone(control: FormControl): {[s: string]: boolean} {
    const regphone = new RegExp(/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/);
    if (control.value && !regphone.test(control.value)) {
      return {'wrongPhone': true};
    }
    return null;
  }
}
